package com.ruoyi.web.controller.manager;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.manager.DevService;
import com.ruoyi.system.service.manager.IDevServiceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务列Controller
 * 
 * @author ruoyi
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/manager/service")
public class DevServiceController extends BaseController
{
    @Autowired
    private IDevServiceService devServiceService;

    /**
     * 查询服务列列表
     */
    @PreAuthorize("@ss.hasPermi('manager:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevService devService)
    {
        startPage();
        List<DevService> list = devServiceService.selectDevServiceList(devService);
        return getDataTable(list);
    }

    /**
     * 导出服务列列表
     */
    @PreAuthorize("@ss.hasPermi('manager:service:export')")
    @Log(title = "导出服务列列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevService devService)
    {
        List<DevService> list = devServiceService.selectDevServiceList(devService);
        ExcelUtil<DevService> util = new ExcelUtil<DevService>(DevService.class);
        util.exportExcel(response, list, "服务列数据");
    }

    /**
     * 获取服务列详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:service:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(devServiceService.selectDevServiceById(id));
    }

    /**
     * 新增服务列
     */
    @PreAuthorize("@ss.hasPermi('manager:service:add')")
    @Log(title = "新增服务列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevService devService)
    {
        return toAjax(devServiceService.insertDevService(devService));
    }

    /**
     * 修改服务列
     */
    @PreAuthorize("@ss.hasPermi('manager:service:edit')")
    @Log(title = "修改服务列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevService devService)
    {
        return toAjax(devServiceService.updateDevService(devService));
    }

    /**
     * 重启服务列
     */
    @PreAuthorize("@ss.hasPermi('manager:service:edit')")
    @Log(title = "重启服务列", businessType = BusinessType.UPDATE)
    @GetMapping("/restart/{id}")
    public AjaxResult restartService(@PathVariable("id") Long id)
    {
        return devServiceService.restartService(id);
    }
    /**
     * 删除服务列
     */
    @PreAuthorize("@ss.hasPermi('manager:service:remove')")
    @Log(title = "删除服务列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devServiceService.deleteDevServiceByIds(ids));
    }
}
